package com.alm.token.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.alm.token.R;
import com.alm.token.base.BaseActivity;
import com.alm.token.ui.data.bean.MessageData;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.ui.persenter.MyPreenter;
import com.alm.token.utils.ActionBarHelper;
import com.alm.token.utils.CommonUtil;
import com.alm.token.utils.EmptyUtils;
import com.alm.token.utils.LogUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MessageDetailActivity extends BaseActivity {

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.date)
    TextView date;
    @BindView(R.id.message)
    TextView message;

    @BindView(R.id.message_flag)
    TextView message_flag;
    @BindView(R.id.message_flagtime)
    TextView message_flagtime;

    private int intentType = 0;
    private UserWalletData.DataBean.SysMsgBean sysMsgBean;
    private MessageData.DataBeanX.MsgListBean.DataBean msgdataBeansBean;

    @Override
    protected MyPreenter initPreenter() {
        return null;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_messagedetail;
    }

    @Override
    protected void initVariables() {
        intentType = getIntent().getIntExtra("intentType", 0);
        new ActionBarHelper(this).setTitle(getString(R.string.platform_hint_notic));
        if (intentType == 1) {//首页公告内容进来
            sysMsgBean = (UserWalletData.DataBean.SysMsgBean) getIntent().getSerializableExtra("sysMsgBean");
        } else {
            msgdataBeansBean = (MessageData.DataBeanX.MsgListBean.DataBean) getIntent().getSerializableExtra("msgdataBeansBean");
        }
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void loadData() {
        title.setText(sysMsgBean != null ? sysMsgBean.getTitle() : msgdataBeansBean != null ? msgdataBeansBean.getTitle() : "标题");
        date.setText(sysMsgBean != null ? CommonUtil.getDateTimeFromMillisecond(sysMsgBean.getCreateTime()).split(" ")[0] :
                msgdataBeansBean != null ? CommonUtil.getDateTimeFromMillisecond(msgdataBeansBean.getCreateTime()).split(" ")[0] : "创建时间");
        String content = sysMsgBean != null ? sysMsgBean.getContent() : msgdataBeansBean != null ? msgdataBeansBean.getContent() : "内容";
        String message_flag_str = "";
        String message_flagtime_str = "";


//        if (content.indexOf("\\n \\nIO TOKEN团队 \\n")!=-1) {
//            LogUtil.e("contains");
//            message_flag_str = "IO TOKEN团队";
//            message_flagtime_str = content.split("\\n \\nIO TOKEN团队 \\n").length >= 2 ? content.split("\\n \\nIO TOKEN团队 \\n")[1] : "";
//            content = content.split("\\n \\nIO TOKEN团队 \\n").length >= 2 ? content.split("\\n \\nIO TOKEN团队 \\n")[0] : content;
//        }
        message.setText(content);
//        message_flag.setText(message_flag_str);
//        message_flagtime.setText(message_flagtime_str);
        message_flag.setVisibility(EmptyUtils.isEmpty(message_flag_str) ? View.GONE : View.VISIBLE);
        message_flagtime.setVisibility(EmptyUtils.isEmpty(message_flagtime_str) ? View.GONE : View.VISIBLE);
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
